﻿/*  Master Page : JavaScript / JQuery  */

function TopSearch() {
    var query = jQuery('#search').val();

    if (query != null || query != "") {
        var sanityCheck = new String();
        sanityCheck = query.replace(/ /g, "");

        if (sanityCheck.length > 0) {
            window.location = '/Search/q/' + escape(query) + '/';
        }
        else {
            jQuery('#search').val("");
        }
    }
    else {
        jQuery('#search').val("");
    }
}

function SideSearch() {
    var query = jQuery('#sidesearch').val();

    if (query != null || query != "") {
        var sanityCheck = new String();
        sanityCheck = query.replace(/ /g, "");

        if (sanityCheck.length > 0) {
            window.location = '/Search/q/' + escape(query) + '/';
        }
        else {
            jQuery('#sidesearch').val("");
        }
    }
    else {
        jQuery('#sidesearch').val("");
    }
}
   

jQuery(document).ready(function() {

    // Searchbox
    jQuery('#searchbox').click(function(event) {
        event.stopPropagation();
    });
    
    // TopSearch enter-key
    jQuery("#search").bind("keydown", function(event) {
        var keycode = (event.keyCode ? event.keyCode : (event.which ? event.which : event.charCode));
        if (keycode == 13) {
            TopSearch();
            return false;
        }
    });
    
    // SideSearch enter-key
    jQuery("#sidesearch").bind("keydown", function(event) {
        var keycode = (event.keyCode ? event.keyCode : (event.which ? event.which : event.charCode));
        if (keycode == 13) {
            SideSearch();
            return false;
        }
    });
    
    // Hover effects
    jQuery('#navmenu').imghover({ suffix: '-hover' });

});
